package cn.tedu.tmall.admin.mall.dao.persist.repository.impl;

import cn.tedu.tmall.admin.mall.dao.persist.mapper.OrderMapper;
import cn.tedu.tmall.admin.mall.dao.persist.repository.IOrderRepository;
import cn.tedu.tmall.admin.mall.pojo.vo.OrderListItemVO;
import cn.tedu.tmall.admin.mall.pojo.vo.OrderStandardVO;
import cn.tedu.tmall.common.pojo.vo.PageData;
import cn.tedu.tmall.common.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class OrderRepository implements IOrderRepository {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Long> listOvertimeUnpaidIdList(int overtimeInMinute) {
        log.debug("开始查询超时未支付的订单id集合");
        return orderMapper.listOvertimeUnpaidIdList(overtimeInMinute);
    }

    @Override
    public int updateStateByBatchIds(List<Long> idList, Integer newState) {
        log.debug("开始执行根据若干个ID批量修改订单状态");
        return orderMapper.updateStateByBatchIds(idList, newState);
    }

    @Override
    public OrderStandardVO getStandardById(Long id) {
        log.debug("开始执行根据id查询订单详情");
        return orderMapper.getStandardById(id);
    }

    @Override
    public PageData<OrderListItemVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行查询订单列表");
        PageHelper.startPage(pageNum,pageSize);
        List<OrderListItemVO> list = orderMapper.list();
        PageInfo<OrderListItemVO> pageInfo=new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }
}
